import java.util.Scanner;

public class Arrays_neighbouring_numbers {

	public static void main(String[] args) {
		
		int k = 0;	
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the array's size: ");
		if(sc.hasNextInt()){
			k = sc.nextInt();		
		}
		int a[] = new int[k];
		System.out.println("Enter the array's numbers: ");
		if(sc.hasNextInt()){
			for(int i = 0; i < a.length ; i++){
					a[i] = sc.nextInt();
					System.out.println("# "+i+ " = "+a[i]+", ");
			}				
		}
		int amin = 0;
		int anext = 0;
		int imin = 0;
		
		for(int i = 2; i < a.length ; i++){			
			if( a[i-2] == a[i-1]){
				amin = a[i-2];
				anext = a[i-1];
				imin = i-2;	
				break;
			}else if(a[i-1] == a[i]){
				amin = a[i-1];
				anext = a[i];
				imin = i-1;	
				break;
			}					
			else if( Math.abs((a[i-2])-(a[i-1])) < Math.abs((a[i-1])-(a[i])) ){
				amin = a[i-2];
				anext = a[i-1];
				imin = i-2;
				}
			else if( Math.abs((a[i-2])-(a[i-1])) > Math.abs((a[i-1])-(a[i])) ){
				amin = a[i-1];
				anext = a[i];
				imin = i-1;	
				}
			else if( Math.abs((a[i-2])-(a[i-1])) == Math.abs((a[i-1])-(a[i])) ){
				amin = a[i-2];
				anext = a[i-1];
				imin = i-2;	
				}
		}
		System.out.println(" The minimal distance is between "+amin+ " and "+anext);
		System.out.println(" The index of the first number in the distance is "+imin);

	}}


